package com.gears_software.bbnetwork.activitys;

import org.androidannotations.annotations.AfterViews;
import org.androidannotations.annotations.Background;
import org.androidannotations.annotations.Bean;
import org.androidannotations.annotations.Click;
import org.androidannotations.annotations.EActivity;
import org.androidannotations.annotations.UiThread;
import org.androidannotations.annotations.ViewById;
import org.androidannotations.annotations.WindowFeature;
import org.androidannotations.annotations.sharedpreferences.Pref;

import com.avos.avoscloud.AVAnalytics;
import com.gears_software.bbnetwork.R;
import com.gears_software.bbnetwork.datas.finders.IBBNetworkFinder;
import com.gears_software.bbnetwork.datas.finders.impl.IBBNetworkFinderImpl;
import com.gears_software.bbnetwork.datas.models.ResultModel;
import com.gears_software.bbnetwork.datas.models.ReturnCode;
import com.gears_software.bbnetwork.utlis.BBNetworkSharedPref_;
import com.gears_software.bbnetwork.utlis.ToastUI;

import android.app.Activity;
import android.view.Window;
import android.widget.TextView;
/**
 * 我的推荐码
 * @author DY-PC
 *
 */
@EActivity(R.layout.activity_recommend_code)
@WindowFeature(Window.FEATURE_NO_TITLE)
public class RecommendActivity extends Activity {
	
	@ViewById
	TextView txt_recommend_code;//推荐码
	
	@Bean(IBBNetworkFinderImpl.class)
	IBBNetworkFinder finder;
	
	@Pref
	BBNetworkSharedPref_ sp;
	
	@Bean
	ToastUI toast;
	
	@AfterViews
	void onCreate(){
		getCode();
	}
	
	@Background
	void getCode(){
		ResultModel<String> res = finder.getRecommendCode(sp.userId().get());
		if(res.getReturnCode().equals(ReturnCode.SUCCEED)){
			setView(res.getResObj());
		}else{
			showTxt("获取推荐码失败！"+res.getMessage());
		}
	}
	
	@UiThread
	void setView(String code){
		txt_recommend_code.setText(code);
	}
	
	@Click
	void iamge_back(){
		finish();
	}
	
	@Override
	protected void onResume(){
		super.onResume();
		 AVAnalytics.onResume(this);
		 
	}
	@Override
	protected void onPause() {
		super.onPause();
		AVAnalytics.onPause(this);
	}
	
	@UiThread
	void showTxt(String txt){
		toast.ShowToast(txt);
	}
}
